package com.suse.jd_system_server.auto.empty;



import lombok.Data;

import java.util.HashMap;
import java.util.Map;


@Data
public class Result<T> {


	 //状态码  0.代表成功  其它代表失败状态码


	private Integer status;


	//提示信息


	private String msg;


	//响应数据


	private T data;


	//总记录数


	private Long count;

	//动态数据
	private Map<String, Object> map = new HashMap<String, Object>();//动态数据，根据需要为返回值添加信息

	/**
	* 构建带分页的返回
	* @param data
	* @param count
	* @return
	*/
	public static Result buildSuccess(Object data,Long count){
		Result result=new Result();
		result.setStatus(0);
		result.setMsg("操作成功");
		result.setData(data);
		result.setCount(count);
		return result;
	}

	/**
	* 构建普通数据的返回
	* @param data
	* @return
	*/
	public static Result buildSuccess(Object data){
		return buildSuccess(data,null);
	}



	/**
	* 构建不需要携带数据的成功
	* @return
	*/
	public static Result buildSuccess(){
		return buildSuccess(null);
	}


	/**
	* 构建失败的消息
	*@param code
	* @param msg
	* @return
	*/
	public static Result buildFail(Integer code,String msg){
		Result result=new Result();
		result.setStatus(code);
		result.setMsg(msg);
		return result;
	}

	/**
	 * 动态添加数据
	 */
	public Result<T> add(String key, Object value){
		this.map.put(key,value);
		return this;
	}


}